<%@page import="com.wowangz.cms.common.utils.MessageObject"%>
<%@ page import="com.wowangz.cms.syscore.utils.MessageResourcesUtils"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<c:set var="systemctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>资金云平台密码重置</title>
<link rel="stylesheet" type="text/css"  href="${systemctx }/resources/css/base.css?t=<%=System.currentTimeMillis() %>" />
<link rel="stylesheet" type="text/css" href="${systemctx }/resources/css/metro/easyui.css?t=<%=System.currentTimeMillis() %>" />
<link rel="stylesheet" type="text/css"  href="${systemctx }/resources/css/index.css?t=<%=System.currentTimeMillis() %>" />
<link rel="stylesheet" type="text/css"  href="${systemctx }/resources/css/validationEngine.jquery.css" />
<link rel="stylesheet" type="text/css"  href="${systemctx }/resources/css/date.css" />
<link rel="stylesheet" type="text/css" href="${systemctx}/resources/ztree/css/zTreeStyle/zTreeStyle.css">

<link rel="stylesheet" type="text/css"  href="${systemctx }/resources/css/common.css" />
<link rel="stylesheet" type="text/css"  href="${systemctx }/resources/css/list.css" />
<link rel="stylesheet" type="text/css"  href="${systemctx }/resources/css/header.css" />
<script type="text/javascript" src="${systemctx }/resources/js/jquery-1.9.1.min.js"></script>
<link href="${systemctx }/resources/css/base.css" rel="stylesheet" type="text/css" media="all" />
<link href="${systemctx }/resources/validform/css/style.css" rel="stylesheet" type="text/css" media="all" />
<link href="${systemctx }/resources/css/list.css" rel="stylesheet" type="text/css" media="all" />
<link rel="stylesheet" href="${systemctx}/resources/css/fileupload.css">

<script type="text/javascript" src="${systemctx }/resources/validform/js/Validform_v5.3.2.js"></script>
<style type="text/css">
	.Validform_checktip {
	    width:auto;
	    display:inline-block;
	    height:auto;
	}
	#showClose:LINK {
		color:#ffffff !important;
	
	}
	a:LANG {
		color:#ffffff !important;
	}
</style>
<script type="text/javascript">
	function showdiv() {
		var height = $("#bg").height();
		$("#bg").css({
			"height" : (height + $(document).scrollTop())
		});
		$("#show").css({
			"top" : $(document).scrollTop() + 200
		});
	    document.getElementById("bg").style.display = "block";
	    document.getElementById("show").style.display = "block";
	}
	function hidediv() {
	    document.getElementById("bg").style.display = 'none';
	    document.getElementById("show").style.display = 'none';
	}
	$(document).ready(function(){
		var show = '<div id="show">'
	        + '<div class="dialog-title">'
	        + '提示信息'
	        + '<a id="showClose" href="javascript:hidediv()" style="display:block;color:#fffff" class="dialog-close">关闭</a>'
	        + '</div>'
	        + '<div id="showText" class="dialog-content">'
	        + '正在进行操作，请稍等...'
	        + '</div>'
	        + '</div>';
	    var bg = '<div id="bg"></div>';
	    $("body").append(bg).append(show);
		$(".registerform").Validform({
			tiptype : 2,
			showAllError : false,
			ajaxPost : true,
			datatype : {
				"same" : function(gets) {
					if (gets != $("#userpassword").val()) {
						return "<%=MessageResourcesUtils.getMessage(request, "common.password.two.password.difference")%>";
					}
				}
			},
			callback:function(data){
				if(data.status == 'y') {
					$("#showText").html('<%=MessageResourcesUtils.getMessage(request, "systemmanage.user.spassword.update.success")%>，正在进行跳转，请稍等...');
					window.location.href="${systemctx}/";
				} else {
					hidediv();
					alert('<%=MessageResourcesUtils.getMessage(request, "systemmanage.user.spassword.update.error")%>');
					return ;
				}
			},
			beforeSubmit: function(confirm) {
				showdiv();
			}
		});
		$('#userpassword').keyup(function(e) {
			var userpassword = $("#userpassword").val();
			if (userpassword.length > 20 || (userpassword.length < 8 && userpassword.length > 0)) {
				$("#userpassword_error").addClass("Validform_wrong").html("<%=MessageResourcesUtils.getMessage(request, "common.password.min.max")%>");
				return false;
			}
			pwStrength($(this).val());
		});
	});
	
	
	// 密码强度校验
	function CharMode(ch) {
		if (ch >= 48 && ch <= 57) //数字   
			return 1;
		if (ch >= 65 && ch <= 90) //大写字母   
			return 2;
		if (ch >= 97 && ch <= 122) //小写   
			return 4;
		else
			return 8; //特殊字符 
	}
	function bitTotal(num) {
		var modes = 0;
		for (var i = 0; i < 4; i++) {
			if (num & 1)
				modes++;
			num >>>= 1;
		}
		return modes;
	}
	function checkStrong(pwd) { //返回密码的强度级别 
		if (pwd.length < 6)
			return 0;
		var Modes = 0;
		for (var i = 0; i < pwd.length; i++) {
			//测试每一个字符的类别并统计一共有多少种模式. 
			Modes |= CharMode(pwd.charCodeAt(i));
		}
		return bitTotal(Modes);
	}
	function pwStrength(pwd) {
		var O_color = "#eeeeee";
		var L_color = "#FF0000";
		var M_color = "#FF9900";
		var H_color = "#33CC00";
		if (pwd == null || pwd == '') {
			$("#userpassword_error").addClass("Validform_wrong").html('<%=MessageResourcesUtils.getMessage(request, "common.password.input.new.password")%>');
			$("#resetPassword").attr('disabled',false)
			document.getElementById("strength_L").style.background = "#FFFFFF";
			document.getElementById("strength_M").style.background = "#FFFFFF";
			document.getElementById("strength_H").style.background = "#FFFFFF";
			return false;
		} else {
			var S_level = checkStrong(pwd);
			switch (S_level) {
				case 0:
					Lcolor = Mcolor = Hcolor = O_color;
				case 1:
					Lcolor = L_color;
					Mcolor = Hcolor = O_color;
					break;
				case 2:
					Lcolor = Mcolor = M_color;
					Hcolor = O_color;
					break;
				default:
					if(pwd.length < 8){
						Lcolor = Mcolor = M_color;
						Hcolor = O_color;
					} else {
						Lcolor = Mcolor = Hcolor = H_color;
					};
				
			};
		}
		document.getElementById("strength_L").style.background = Lcolor;
		document.getElementById("strength_M").style.background = Mcolor;
		document.getElementById("strength_H").style.background = Hcolor;
		$("#userpassword_error").addClass("Validform_wrong").html("");
		if(S_level == 0 || S_level == 1){
			$("#userpassword_error").addClass("Validform_wrong").html('<%=MessageResourcesUtils.getMessage(request, "common.password.input.new.password.weak")%>');
			$("#resetPassword").attr('disabled',true);
			return false;
		}else {
			$("#resetPassword").attr('disabled',false);
			$("#userpassword_error").removeClass("Validform_wrong").addClass("Validform_right").html('<%=MessageResourcesUtils.getMessage(request, "common.password.input.new.password.pass")%>');
		}
		return;
	};
</script>
</head>
<body>
	<form class="registerform" action="${systemctx}/systemmanage/manageUser/resetUserPassword.json" name="reset" id="reset">
		<div class="panel-header">
			<div class="panel-title">
				资金云平台密码重置
			</div>
		</div>
		<c:choose>
			<c:when test="${flag=='INVALIDE'}">
				<div class="pageBody">
					你的邮件已经过期，请联系管理员.
				</div>
			</c:when>
			<c:otherwise>
				<div class="pageBody">
					<div class="form-group">
						<input type="hidden" name="id" id="id" value="${id}">
						<input type="hidden" name="isBatch" id="isBatch" value="${isBatch}"/>
						<ul>
							<li class="liw">
								<i></i>
								<label>
									<%=MessageResourcesUtils.getMessage(request, "systemmanage.user.password.name.new")%>
								</label>
								<span>
									<input ajaxurl="${systemctx}/systemmanage/resetManageUser/isValidByTop.json?userid=${id}" type="password" value="" name="password" id="userpassword" 
										datatype="*8-20" 
										nullmsg="<%=MessageResourcesUtils.getMessage(request, "common.password.input.new.password") %>" 
										errormsg="<%=MessageResourcesUtils.getMessage(request, "common.password.min.max") %>" />
								</span>
								<span>
									<div class="Validform_checktip" id="userpassword_error"></div>
								</span>
							</li>
						</ul>
						<ul>
							<li>
								<div class="pass-vali">
									<p id="strength_L"><%=MessageResourcesUtils.getMessage(request, "common.password.weak") %></p>
									<p id="strength_M"><%=MessageResourcesUtils.getMessage(request, "common.password.normal") %></p>
									<p id="strength_H"><%=MessageResourcesUtils.getMessage(request, "common.password.strong") %></p>
								</div>
							</li>
						</ul>
						<ul>
							<li>
								<i></i>
								<label>
									<%=MessageResourcesUtils.getMessage(request, "systemmanage.user.password.name.snew")%>
								</label>
								<span>
									<input type="password" value="" id="userpassword"
										name="userpassword"
										nullmsg="<%=MessageResourcesUtils.getMessage(request, "common.password.input.new.password")%>"
										datatype="same,*8-20"
										errormsg="<%=MessageResourcesUtils.getMessage(request, "common.password.min.max")%>" />
								</span>
								<span>
									<div class="Validform_checktip"></div>
								</span>
							</li>
						</ul>
					</div>
				</div>
				<div class="button-group">
					<input type="submit" class="btn btn-default" id="resetPassword" name="resetPassword" value='<%=MessageResourcesUtils.getMessage(request, "systemmanage.User.add.pwd")%>' />
					<a href="${systemctx}">[ 登录 ]</a>
				</div>
			</c:otherwise>
		</c:choose>
	</form>
</body>
</html>